/**
 * Description:
 * Class Name:Person
 * Date:2022/1/29 14:31
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第6章_面向对象_下._6_4_final修饰符;

class Name{
    private String firstName;
    private String lastName;
    public Name(){}
    public Name(String firstName, String lastName){
        this.firstName = firstName;
        this.lastName = lastName;
    }
    public String getFirstName(){
        return this.firstName;
    }
    public String getLastName(){
        return this.lastName;
    }
    public void setFirstName(String firstName){
        this.firstName = firstName;
    }
    public void setLastName(String lastName){
        this.lastName = lastName;
    }
}

public class ImmutablePerson {
    private final Name name;
    public ImmutablePerson(Name name){
        this.name = name;
    }
    public Name getName(){
        return name;
    }
    public static void main(String[] args) {
        var n = new Name("悟空", "孙");
        var p = new ImmutablePerson(n);
        System.out.println(p.getName().getFirstName());
        n.setFirstName("八戒");
        System.out.println(p.getName().getFirstName());
    }
}
